{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 课本示例编写"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 二分查找"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-22T15:57:44.633053Z",
     "start_time": "2019-05-22T15:57:44.624036Z"
    }
   },
   "outputs": [],
   "source": [
    "def binaryfind(data, target, low, high):\n",
    "    mid = (low + high) // 2\n",
    "    if target == data[mid]:\n",
    "        return True\n",
    "    elif target < data[mid]:\n",
    "        return binaryfind(data, target, low, mid-1)\n",
    "    else:\n",
    "        return binaryfind(data, target, mid+1, high)            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-22T15:58:58.386745Z",
     "start_time": "2019-05-22T15:58:58.378732Z"
    }
   },
   "outputs": [],
   "source": [
    "def shunxufind(data, target):\n",
    "    length = len(data)\n",
    "    for i in range(length):\n",
    "        if data[i] == target:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-22T15:57:46.877882Z",
     "start_time": "2019-05-22T15:57:46.872893Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]\n",
    "print(binaryfind(data, 16, 0, 20))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-22T15:59:00.506256Z",
     "start_time": "2019-05-22T15:59:00.497281Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]\n",
    "print(shunxufind(data, 16))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 斐波那契数列的递归优化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 垃圾斐波那契递归方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T12:52:40.981956Z",
     "start_time": "2019-05-23T12:52:40.973973Z"
    }
   },
   "outputs": [],
   "source": [
    "def bad_fibonacci(n):\n",
    "    if n <= 1:\n",
    "        return n\n",
    "    else:\n",
    "        return bad_fibonacci(n-1) + bad_fibonacci(n-2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T13:02:10.749789Z",
     "start_time": "2019-05-23T13:02:10.735815Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 1, 2, 3, 5, 8, 13]\n"
     ]
    }
   ],
   "source": [
    "print([bad_fibonacci(i) for i in range(8)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 优化后的解法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T13:35:48.924034Z",
     "start_time": "2019-05-23T13:35:48.913060Z"
    }
   },
   "outputs": [],
   "source": [
    "def good_fibonacci(n):\n",
    "    if n <= 1:\n",
    "        return (n,0)\n",
    "    else:\n",
    "        (a,b) = good_fibonacci(n-1)\n",
    "        return (a+b,a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T13:45:09.650927Z",
     "start_time": "2019-05-23T13:45:09.641955Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 1, 1, 2, 3, 5, 8, 13]\n"
     ]
    }
   ],
   "source": [
    "print([good_fibonacci(i)[0] for i in range(8)])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 用于计算幂的递归算法"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 一般的递归计算——O(n)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T14:31:21.277815Z",
     "start_time": "2019-05-23T14:31:21.269826Z"
    }
   },
   "outputs": [],
   "source": [
    "def power(x, n):\n",
    "    if n == 0:\n",
    "        return 1\n",
    "    else:\n",
    "        return x*power(x, n-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T14:31:42.471846Z",
     "start_time": "2019-05-23T14:31:42.465861Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1024\n"
     ]
    }
   ],
   "source": [
    "print(power(2, 10))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 优化过后的递归计算——O(logn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T14:50:52.664028Z",
     "start_time": "2019-05-23T14:50:52.658039Z"
    }
   },
   "outputs": [],
   "source": [
    "def new_power(x, n):\n",
    "    if n == 0:\n",
    "        return 1\n",
    "    else:\n",
    "        partial = power(x, n//2)\n",
    "        result = partial * partial\n",
    "        if n % 2 == 1:\n",
    "            result *= x\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-23T14:51:06.862938Z",
     "start_time": "2019-05-23T14:51:06.855959Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1024\n"
     ]
    }
   ],
   "source": [
    "print(power(2, 10))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 巩固题"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.9 写一个简短的递归Python函数，用于在不使用任何循环的条件下查找一个序列中的最小值和最大值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-24T13:51:44.708489Z",
     "start_time": "2019-05-24T13:51:44.696504Z"
    }
   },
   "outputs": [],
   "source": [
    "def findmaxandmin(data, low, high):\n",
    "    global Max, Min\n",
    "    if low > high:\n",
    "        return (Max,Min)\n",
    "    elif high == len(data) - 1:\n",
    "        Max = max(data[low], data[high])\n",
    "        Min = min(data[low], data[high])\n",
    "        return findmaxandmin(data, low+1, high-1)\n",
    "    else:\n",
    "        Max = max(data[low], data[high], Max)\n",
    "        Min = min(data[low], data[high], Min)\n",
    "        return findmaxandmin(data, low+1, high-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-24T13:51:46.104839Z",
     "start_time": "2019-05-24T13:51:46.095868Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(9, 1)\n"
     ]
    }
   ],
   "source": [
    "data = [5,2,6,8,1,6,9,3]\n",
    "print(findmaxandmin(data, 0, 7))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.10 在只使用加法和整数除法的情况下，描述一个递归算法，来计算以2位底的n的对数的整数部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-24T15:44:07.210484Z",
     "start_time": "2019-05-24T15:44:07.206495Z"
    }
   },
   "outputs": [],
   "source": [
    "def findint(x, i=0):\n",
    "    if x < 2:\n",
    "        return i\n",
    "    else:\n",
    "        i += 1\n",
    "        return findint(x/2, i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-24T15:44:42.189539Z",
     "start_time": "2019-05-24T15:44:42.184555Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "source": [
    "print(findint(15))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.12 在只使用加法和减法的情况下，给出一个递归算法，来计算两个正整数m和n的乘积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-25T02:27:18.785221Z",
     "start_time": "2019-05-25T02:27:18.779233Z"
    }
   },
   "outputs": [],
   "source": [
    "def mymulti(m, n, i=0):\n",
    "    global add_res\n",
    "    if i >= n:\n",
    "        return add_res\n",
    "    elif i == 0:\n",
    "        add_res = m\n",
    "        return mymulti(m, n, i+1)\n",
    "    else:\n",
    "        add_res += m\n",
    "        return mymulti(m, n, i+1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-25T02:27:19.638578Z",
     "start_time": "2019-05-25T02:27:19.632589Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20\n"
     ]
    }
   ],
   "source": [
    "print(mymulti(5, 4))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.14 汉诺塔问题"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-25T12:53:08.527706Z",
     "start_time": "2019-05-25T12:53:08.514741Z"
    }
   },
   "outputs": [],
   "source": [
    "def hanovi(n, a, b, c, i=0):\n",
    "    if n == 1:\n",
    "        print(a, '->', c)\n",
    "    else:\n",
    "        hanovi(n-1, a, c, b,)\n",
    "        print(a, '->', c)\n",
    "        hanovi(n-1, b, c, a, i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-25T13:11:07.521141Z",
     "start_time": "2019-05-25T13:11:07.515156Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A -> C\n",
      "A -> B\n",
      "C -> A\n",
      "A -> C\n",
      "B -> C\n",
      "B -> A\n",
      "C -> B\n"
     ]
    }
   ],
   "source": [
    "hanovi(3, 'A', 'B', 'C')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.15 编写一个递归函数，该函数将输出一个含有n个元素的集合的所有子集(没有任何重复的子集)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 我的递归解法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-28T08:07:54.630706Z",
     "start_time": "2019-05-28T08:07:54.623725Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a']\n",
      "['b']\n",
      "['a', 'b']\n",
      "['c']\n",
      "['a', 'c']\n",
      "['b', 'c']\n",
      "['a', 'b', 'c']\n",
      "['d']\n",
      "['a', 'd']\n",
      "['b', 'd']\n",
      "['a', 'b', 'd']\n",
      "['c', 'd']\n",
      "['a', 'c', 'd']\n",
      "['b', 'c', 'd']\n",
      "['a', 'b', 'c', 'd']\n",
      "[]\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "def findson(data, i=1):\n",
    "    if i == 2**len(data):\n",
    "        print([])\n",
    "    else:\n",
    "        subset = []\n",
    "        for j in range(len(data)):\n",
    "            if (i >> j) % 2 == 1:\n",
    "                subset += data[j]\n",
    "        print(subset)\n",
    "        return findson(data, i+1)\n",
    "print(findson(['a','b','c','d']))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 标准递归解法1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-28T07:44:46.371170Z",
     "start_time": "2019-05-28T07:44:46.365197Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[], ['a'], ['b'], ['b', 'a'], ['c'], ['c', 'a'], ['c', 'b'], ['c', 'b', 'a'], ['d'], ['d', 'a'], ['d', 'b'], ['d', 'b', 'a'], ['d', 'c'], ['d', 'c', 'a'], ['d', 'c', 'b'], ['d', 'c', 'b', 'a']]\n"
     ]
    }
   ],
   "source": [
    "def PowerSetsRecursive(items):\n",
    "    \"\"\"Use recursive call to return all subsets of items, include empty set\"\"\"\n",
    "    \n",
    "    if len(items) == 0:\n",
    "        #if the lsit is empty, return the empty list\n",
    "        return [[]]\n",
    "    \n",
    "    subsets = []\n",
    "    first_elt = items[0] #first element\n",
    "    rest_list = items[1:]\n",
    "    \n",
    "    #Strategy:Get all subsets of rest_list; for each of those subsets, a full subset list\n",
    "    #will contain both the original subset as well as a version of the sebset that contains the first_elt\n",
    "    \n",
    "    for partial_sebset in PowerSetsRecursive(rest_list):\n",
    "        subsets.append(partial_sebset)\n",
    "        next_subset = partial_sebset[:] +[first_elt]\n",
    "        subsets.append(next_subset)\n",
    "    return subsets\n",
    "print(PowerSetsRecursive(['a','b','c','d']))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 标准递归解法2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-28T07:49:26.330623Z",
     "start_time": "2019-05-28T07:49:26.326637Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[], ['a'], ['b'], ['a', 'b'], ['c'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c'], ['d'], ['a', 'd'], ['b', 'd'], ['a', 'b', 'd'], ['c', 'd'], ['a', 'c', 'd'], ['b', 'c', 'd'], ['a', 'b', 'c', 'd']]\n"
     ]
    }
   ],
   "source": [
    "def PowerSetsRecursive2(items):\n",
    "    # the power set of the empty set has one element, the empty set\n",
    "    result = [[]]\n",
    "    for x in items:\n",
    "        result.extend([subset + [x] for subset in result])\n",
    "    return result \n",
    "print(PowerSetsRecursive2(['a','b','c','d']))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 标准循环解法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-28T08:05:35.201701Z",
     "start_time": "2019-05-28T08:05:35.195745Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[], ['a'], ['b'], ['a', 'b'], ['c'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c'], ['d'], ['a', 'd'], ['b', 'd'], ['a', 'b', 'd'], ['c', 'd'], ['a', 'c', 'd'], ['b', 'c', 'd'], ['a', 'b', 'c', 'd']]\n"
     ]
    }
   ],
   "source": [
    "def PowerSetsBinary(items):\n",
    "    #generate all combination of N items\n",
    "    N = len(items)\n",
    "    #enumerate the 2**N possible combinations\n",
    "    for i in range(2**N):\n",
    "        combo = []\n",
    "        for j in range(N):\n",
    "            #test jth bit of integer i\n",
    "            if(i >> j ) % 2 == 1:\n",
    "                combo.append(items[j])\n",
    "        yield combo\n",
    "data = ['a','b','c','d'] \n",
    "print(list(PowerSetsBinary(data)))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.16 编写一个简短的递归Python函数，它接受一个字符串s并且输出其逆置字符串。例如字符串'pots&pans'的逆置字符串为'snap&stop'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-28T08:48:53.998656Z",
     "start_time": "2019-05-28T08:48:53.995633Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "gfedcba\n"
     ]
    }
   ],
   "source": [
    "def reverse(s):\n",
    "    if s == '':\n",
    "        return s\n",
    "    else:\n",
    "        return reverse(s[1:]) + s[0]\n",
    "# print(reverse('hello'))\n",
    "print(reverse('abcdefg'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.17 编写一个简短的递归Python函数，确定一个字符串s是否是它的一个回文字符串，也就是说，该字符串与其逆置字符串相同。例如，字符串'racecar'和'gphangasalamiimalasagnahog'是回文字符串。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 我的代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-29T11:06:58.323272Z",
     "start_time": "2019-05-29T11:06:58.317287Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "def huiwen(s, mybool=True):\n",
    "    N = len(s)\n",
    "    if mybool==False:\n",
    "        return mybool\n",
    "    elif N<=1:\n",
    "        return mybool\n",
    "    #elif N==2:\n",
    "    #    if s[0] == s[1]:\n",
    "     #       return True\n",
    "      #  else:\n",
    "       #     return False\n",
    "    else:\n",
    "        if s[0]==s[N-1]:\n",
    "            mybool = True\n",
    "        else:\n",
    "            mybool = False\n",
    "        #print(s,s[1:N-1], mybool)\n",
    "        return huiwen(s[1:N-1], mybool)\n",
    "print(huiwen('abcba'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 简洁代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-29T11:07:01.443685Z",
     "start_time": "2019-05-29T11:07:01.433717Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "def isHuiWen(str):\n",
    "    if(len(str) <2):\n",
    "        return True\n",
    "    if str[0] !=str[-1]:\n",
    "        return False\n",
    "    return isHuiWen(str[1:-1])\n",
    "print(isHuiWen('abccba'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.18 使用递归编写一个Python函数，确定字符串s中是否元音字母比辅音字母多。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-29T11:39:41.549562Z",
     "start_time": "2019-05-29T11:39:41.537586Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "def comparealpha(s, alpha1=0, alpha2=0, i=0):\n",
    "    N = len(s)\n",
    "    if i == N-1:\n",
    "        return (alpha1>alpha2)\n",
    "    else:\n",
    "        if ord(s[i]) in range(65,91) or ord(s[i]) in range(97,123):\n",
    "            if s[i] in ['a','e','o','u','i','A','E','O','U','I']:\n",
    "                alpha1 += 1\n",
    "            else:\n",
    "                alpha2 += 1\n",
    "        return comparealpha(s, alpha1, alpha2, i+1)\n",
    "print(comparealpha('Hello, World!'))\n",
    "print(comparealpha('Hellooo!'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 4.19 编写一个简短的递归Python函数，用于重新排列一个整数值序列，使得所有偶数值出现在所有奇数值的前面。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-05-29T12:06:16.460807Z",
     "start_time": "2019-05-29T12:06:16.451840Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2, 4, 6, 8, 1, 3, 5, 7, 9]\n"
     ]
    }
   ],
   "source": [
    "def neworder(data, odd=[], even=[], i=0):\n",
    "    N = len(data)\n",
    "    if i==N:\n",
    "        even.extend(odd)\n",
    "        return even\n",
    "    else:\n",
    "        if data[i] % 2 == 0:\n",
    "            even.append(data[i])\n",
    "            #print(even)\n",
    "        else:\n",
    "            odd.append(data[i])\n",
    "            #print(odd)\n",
    "        return neworder(data,odd,even,i+1)\n",
    "data = [1,2,3,4,5,6,7,8,9]\n",
    "print(neworder(data))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
